const alias = require('./alias.config');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports = {
    chainWebpack: config => {
        for (const aliasKey in alias.resolve.alias) {
            config.resolve.alias.set(aliasKey, alias.resolve.alias[aliasKey]);
        }
    },
    configureWebpack: {
        plugins: [
            new CopyWebpackPlugin({
                patterns: [
                    {
                        from: path.join(__dirname, 'src/cloud_functions'),
                        to: path.join(__dirname, 'dist', process.env.NODE_ENV === 'production' ? 'build' : 'dev', process.env.UNI_PLATFORM, 'functions'),
                        globOptions: {
                            gitignore: true
                        }
                    }
                ]
            })
        ]
    }
};
